package main.scala.chapter02

object Test36_Score {
  def main(args: Array[String]): Unit = {
    val m = List(
      Map("姓名"->"张三","语文"->87,"数学"->88,"英语"->78),
      Map("姓名"->"李四","语文"->82,"数学"->81,"英语"->90),
      Map("姓名"->"王五","语文"->80,"数学"->74,"英语"->79))
    //计算所有科目的平均分
    val Chinese = m.map(e => {
      e.get("语文").head.toString.toInt
    })
    println(Chinese.sum/Chinese.size)
    val Math = m.map(e => {
      e.get("数学").head.toString.toInt
    })
    println(Math.sum/Math.size)
    val English = m.map(e => {
      e.get("英语").head.toString.toInt
    })
    println(English.sum/English.size)
    //每一个人的平均成绩
    println(m.map(e=>{e.values})
      .map(e=>{e.head->(e.takeRight(3)
      .map(e=>e.toString.toInt).sum/3)}))
    println(m.map(e=>{e.values})
      .map(e=>{e.head->(e.takeRight(3)
        .reduce((x,y)=>x.toString.toInt+y.toString.toInt).toString.toInt/3)}))
  }
}
